test_arr = [line.strip().split('\t') for line in open('data/2015/15-rest-test.tsv')]
test_out_arr = [line.strip().split('\t') for line in open('data/result/ASK-RoBERTa/15-rest_test_out.tsv.0.77')]
true_count = 0
ori_pos_count = 326
ori_neg_count = 182
ori_neu_count = 34
pre_pos_count = 0
pre_neg_count = 0
pre_neu_count = 0
pre_pos_true_count = 0
pre_neg_true_count = 0
pre_neu_true_count = 0
for num in range(0,542):
    polarity = 2
    if len(test_arr[num + 1]) < 4:
        print(test_arr)
    true_result = int(test_arr[num + 1][3])
    prob = eval(test_out_arr[num][2])[0]
    if prob > 0.55:
        polarity = 0
        pre_pos_count += 1
        if true_result == polarity:
            pre_pos_true_count += 1
    elif prob < 0.45:
        polarity = 1
        pre_neg_count += 1
        if true_result == polarity:
            pre_neg_true_count += 1
    if polarity == 2:
        pre_neu_count += 1
        if true_result == polarity:
            pre_neu_true_count += 1
    if true_result == polarity:
        true_count += 1


pre_pos = pre_pos_true_count / ori_pos_count
recall_pos = pre_pos_true_count / pre_pos_count
f1_pos = 2 * pre_pos * recall_pos / (pre_pos + recall_pos)

pre_neg = pre_neg_true_count / ori_neg_count
recall_neg = pre_neg_true_count / pre_neg_count
f1_neg = 2 * pre_neg * recall_neg / (pre_neg + recall_neg)

pre_neu = pre_neu_true_count / ori_neu_count
recall_neu = pre_neu_true_count / pre_neu_count
f1_neu = 2 * pre_neu * recall_neu / (pre_neu + recall_neu)

macf1 = (f1_pos + f1_neg + f1_neu) / 3
# print(f1_pos)
# print(f1_neg)
# print(f1_neu)
print(true_count / 542)
print(macf1)
